{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第一周作业"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 九九乘法表\n",
    "###  使用while和for…in两个循环分别输出四种九九乘法表效果（共计8个）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常左下角写法自己的for思路\n",
      "1*1=1 \n",
      "1*2=2 2*2=4 \n",
      "1*3=3 2*3=6 3*3=9 \n",
      "1*4=4 2*4=8 3*4=12 4*4=16 \n",
      "1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 \n",
      "1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 \n",
      "1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 \n",
      "1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 \n",
      "1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('正常左下角写法自己的for思路')\n",
    "for i in range(1,10):  # 把i看做行\n",
    "    j = 1\n",
    "    print(\"{}*{}={}\".format(j, i, i * j), end=' ')\n",
    "    if i == j:\n",
    "        print('')\n",
    "    while i > j:\n",
    "        j+=1\n",
    "        print(\"{}*{}={}\".format(j, i, i * j), end=' ')\n",
    "        if i == j:\n",
    "            print('')\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常左下角写法修改的for思路\n",
      " 1 * 1 = 1  \n",
      " 1 * 2 = 2   2 * 2 = 4  \n",
      " 1 * 3 = 3   2 * 3 = 6   3 * 3 = 9  \n",
      " 1 * 4 = 4   2 * 4 = 8   3 * 4 =12   4 * 4 =16  \n",
      " 1 * 5 = 5   2 * 5 =10   3 * 5 =15   4 * 5 =20   5 * 5 =25  \n",
      " 1 * 6 = 6   2 * 6 =12   3 * 6 =18   4 * 6 =24   5 * 6 =30   6 * 6 =36  \n",
      " 1 * 7 = 7   2 * 7 =14   3 * 7 =21   4 * 7 =28   5 * 7 =35   6 * 7 =42   7 * 7 =49  \n",
      " 1 * 8 = 8   2 * 8 =16   3 * 8 =24   4 * 8 =32   5 * 8 =40   6 * 8 =48   7 * 8 =56   8 * 8 =64  \n",
      " 1 * 9 = 9   2 * 9 =18   3 * 9 =27   4 * 9 =36   5 * 9 =45   6 * 9 =54   7 * 9 =63   8 * 9 =72   9 * 9 =81  \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('正常左下角写法修改的for思路')\n",
    "for row in range(1, 10):\n",
    "    for col in range(1, 10):\n",
    "        if col <= row:\n",
    "         print(\"{:^3d}*{:^3d}={:^3d}\".format(col, row, row * col), end=' ')\n",
    "         #\t{:^3d} 中间对齐 (宽度为3)\n",
    "    print('')\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常左下角写法学习后修改的for思路\n",
      "1*1=1    \n",
      "1*2=2    2*2=4    \n",
      "1*3=3    2*3=6    3*3=9    \n",
      "1*4=4    2*4=8    3*4=12   4*4=16   \n",
      "1*5=5    2*5=10   3*5=15   4*5=20   5*5=25   \n",
      "1*6=6    2*6=12   3*6=18   4*6=24   5*6=30   6*6=36   \n",
      "1*7=7    2*7=14   3*7=21   4*7=28   5*7=35   6*7=42   7*7=49   \n",
      "1*8=8    2*8=16   3*8=24   4*8=32   5*8=40   6*8=48   7*8=56   8*8=64   \n",
      "1*9=9    2*9=18   3*9=27   4*9=36   5*9=45   6*9=54   7*9=63   8*9=72   9*9=81   \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "# 九九乘法表的左下角写法\n",
    "print('正常左下角写法学习后修改的for思路')\n",
    "# 1、把乘法表左上角考虑成（1，1）坐标点，每个乘法表等于row*col\n",
    "# 2、输出是一行一行输出的，所以每一行输出后要求换行。\n",
    "# 3、每一行的行号就是列从1到行号的循环。\n",
    "# 4、对格式进行修正，\n",
    "for row in range(1, 10):\n",
    "    for col in range(1, row + 1):\n",
    "        print(\"{}*{}={:<4}\".format(col, row, row * col), end=' ')\n",
    "    print('')\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常左下角写法的while思路\n",
      "1*1=1   \n",
      "1*2=2   2*2=4   \n",
      "1*3=3   2*3=6   3*3=9   \n",
      "1*4=4   2*4=8   3*4=12  4*4=16  \n",
      "1*5=5   2*5=10  3*5=15  4*5=20  5*5=25  \n",
      "1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36  \n",
      "1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49  \n",
      "1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64  \n",
      "1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81  \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('正常左下角写法的while思路')\n",
    "row = 1\n",
    "# 行的初始值为1\n",
    "while row <= 9:\n",
    "    col = 1\n",
    "    # 列的初始值为1\n",
    "    while col <= row:\n",
    "        print('{}*{}={:<4d}'.format(col, row, row * col),end='')\n",
    "        col += 1\n",
    "    print('')\n",
    "    row += 1\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "九九乘法表的左上角for写法\n",
      "1*9=9    2*9=18   3*9=27   4*9=36   5*9=45   6*9=54   7*9=63   8*9=72   9*9=81   \n",
      "1*8=8    2*8=16   3*8=24   4*8=32   5*8=40   6*8=48   7*8=56   8*8=64   \n",
      "1*7=7    2*7=14   3*7=21   4*7=28   5*7=35   6*7=42   7*7=49   \n",
      "1*6=6    2*6=12   3*6=18   4*6=24   5*6=30   6*6=36   \n",
      "1*5=5    2*5=10   3*5=15   4*5=20   5*5=25   \n",
      "1*4=4    2*4=8    3*4=12   4*4=16   \n",
      "1*3=3    2*3=6    3*3=9    \n",
      "1*2=2    2*2=4    \n",
      "1*1=1    \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('九九乘法表的左上角for写法')\n",
    "for row in range(9,0,-1):\n",
    "    for col in range(1,row+1):\n",
    "        print(\"{}*{}={:<4}\".format(col, row, row * col), end=' ')\n",
    "    print('')\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常左上角写法的while思路\n",
      "1*9=9   1*8=8   1*7=7   1*6=6   1*5=5   1*4=4   1*3=3   1*2=2   1*1=1   \n",
      "1*8=8   1*7=7   1*6=6   1*5=5   1*4=4   1*3=3   1*2=2   1*1=1   \n",
      "1*7=7   1*6=6   1*5=5   1*4=4   1*3=3   1*2=2   1*1=1   \n",
      "1*6=6   1*5=5   1*4=4   1*3=3   1*2=2   1*1=1   \n",
      "1*5=5   1*4=4   1*3=3   1*2=2   1*1=1   \n",
      "1*4=4   1*3=3   1*2=2   1*1=1   \n",
      "1*3=3   1*2=2   1*1=1   \n",
      "1*2=2   1*1=1   \n",
      "1*1=1   \n",
      "\n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('正常左上角写法的while思路')\n",
    "row = 9\n",
    "while row >=0:\n",
    "    col = 1\n",
    "    n = row\n",
    "    # 被乘数的初始值为row\n",
    "    while col <=n:\n",
    "        print('{}*{}={:<4d}'.format(col, n, n * col),end='')\n",
    "        n -=1\n",
    "    print('')\n",
    "    col += 1\n",
    "    row -=1\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "九九乘法表的右下角for写法\n",
      "                                                                        1*1=1    \n",
      "                                                               2*1=2    2*2=4    \n",
      "                                                      3*1=3    3*2=6    3*3=9    \n",
      "                                             4*1=4    4*2=8    4*3=12   4*4=16   \n",
      "                                    5*1=5    5*2=10   5*3=15   5*4=20   5*5=25   \n",
      "                           6*1=6    6*2=12   6*3=18   6*4=24   6*5=30   6*6=36   \n",
      "                  7*1=7    7*2=14   7*3=21   7*4=28   7*5=35   7*6=42   7*7=49   \n",
      "         8*1=8    8*2=16   8*3=24   8*4=32   8*5=40   8*6=48   8*7=56   8*8=64   \n",
      "9*1=9    9*2=18   9*3=27   9*4=36   9*5=45   9*6=54   9*7=63   9*8=72   9*9=81   \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('九九乘法表的右下角for写法')\n",
    "for row in range(1, 10):\n",
    "    for n in range(1, 10 - row):\n",
    "    # 先打印对应的空格\n",
    "    # 每一行的空格分别是8，7，6，5，4，3，2，1，0\n",
    "        print(' ' * 9 , end='')\n",
    "    for col in range(1, row + 1):\n",
    "    # 然后再将每行的乘法表正常输出\n",
    "        print(\"{}*{}={:<4}\".format(row, col, row * col), end=' ')\n",
    "    print('')\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常右下角写法的while思路\n",
      "                                                                        1*1=1    \n",
      "                                                               2*2=4    1*2=2    \n",
      "                                                      3*3=9    2*3=6    1*3=3    \n",
      "                                             4*4=16   3*4=12   2*4=8    1*4=4    \n",
      "                                    5*5=25   4*5=20   3*5=15   2*5=10   1*5=5    \n",
      "                           6*6=36   5*6=30   4*6=24   3*6=18   2*6=12   1*6=6    \n",
      "                  7*7=49   6*7=42   5*7=35   4*7=28   3*7=21   2*7=14   1*7=7    \n",
      "         8*8=64   7*8=56   6*8=48   5*8=40   4*8=32   3*8=24   2*8=16   1*8=8    \n",
      "9*9=81   8*9=72   7*9=63   6*9=54   5*9=45   4*9=36   3*9=27   2*9=18   1*9=9    \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('正常右下角写法的while思路')\n",
    "row = 1\n",
    "# 行的初始值为1\n",
    "# 列的初始值为1\n",
    "while row <= 9:\n",
    "    n = 9-row\n",
    "    while n > 0:\n",
    "        print(' ' * 9, end='')\n",
    "        n -= 1\n",
    "    col = row\n",
    "    while col >0:\n",
    "        print('{}*{}={:<5}'.format(col, row, row * col), end='')\n",
    "        col -= 1\n",
    "    print('')\n",
    "    row += 1\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "九九乘法表的右上角for写法\n",
      "9*9=81   9*8=72   9*7=63   9*6=54   9*5=45   9*4=36   9*3=27   9*2=18   9*1=9    \n",
      "         8*8=64   8*7=56   8*6=48   8*5=40   8*4=32   8*3=24   8*2=16   8*1=8    \n",
      "                  7*7=49   7*6=42   7*5=35   7*4=28   7*3=21   7*2=14   7*1=7    \n",
      "                           6*6=36   6*5=30   6*4=24   6*3=18   6*2=12   6*1=6    \n",
      "                                    5*5=25   5*4=20   5*3=15   5*2=10   5*1=5    \n",
      "                                             4*4=16   4*3=12   4*2=8    4*1=4    \n",
      "                                                      3*3=9    3*2=6    3*1=3    \n",
      "                                                               2*2=4    2*1=2    \n",
      "                                                                        1*1=1    \n",
      "====================\n"
     ]
    }
   ],
   "source": [
    "print('九九乘法表的右上角for写法')\n",
    "for row in range(9, 0, -1):\n",
    "    for n in range(9, 0, -1):\n",
    "    # 即每一行的需要空位数分别是：0，1，2，3，4，5，6，7，8\n",
    "    # n的取值分别为9，8，7，6，5，4，3，2，1\n",
    "        if n > row:\n",
    "            print(' ' * 9 , end='')\n",
    "    for col in range(row, 0, -1):\n",
    "    # 开始的列的值取决于行的初试数值\n",
    "        print(\"{}*{}={:<4}\".format(row, col, row * col), end=' ')\n",
    "    print('')\n",
    "print('=' * 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "正常右上角写法的while思路\n",
      "9*9=81   9*8=72   9*7=63   9*6=54   9*5=45   9*4=36   9*3=27   9*2=18   9*1=9    \n",
      "         8*8=64   8*7=56   8*6=48   8*5=40   8*4=32   8*3=24   8*2=16   8*1=8    \n",
      "                  7*7=49   7*6=42   7*5=35   7*4=28   7*3=21   7*2=14   7*1=7    \n",
      "                           6*6=36   6*5=30   6*4=24   6*3=18   6*2=12   6*1=6    \n",
      "                                    5*5=25   5*4=20   5*3=15   5*2=10   5*1=5    \n",
      "                                             4*4=16   4*3=12   4*2=8    4*1=4    \n",
      "                                                      3*3=9    3*2=6    3*1=3    \n",
      "                                                               2*2=4    2*1=2    \n",
      "                                                                        1*1=1    \n",
      "====================================================================================================\n",
      "====================================================================================================\n",
      "====================================================================================================\n"
     ]
    }
   ],
   "source": [
    "print('正常右上角写法的while思路')\n",
    "row = 9\n",
    "while row >= 1:\n",
    "    col = row\n",
    "    n = 0\n",
    "    while n < 9 - row:\n",
    "        print(' ' * 9, end='')\n",
    "        n += 1\n",
    "    while col >=1:\n",
    "        print('{}*{}={:<5d}'.format(row, col, row * col),end='')\n",
    "        col -= 1\n",
    "    print('')\n",
    "    row -= 1\n",
    "print('=' * 100)\n",
    "print('=' * 100)\n",
    "print('=' * 100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用文件和目录操作，定义一个统计指定目录大小的函数（注意目录中还有子目录）。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pygal目录下所有文件和文件夹的大小总和为： 1503810\n",
      "====================================================================================================\n",
      "====================================================================================================\n",
      "====================================================================================================\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "@Descripttion: \n",
    "@version: \n",
    "@Author: dkolli\n",
    "@Date: 2019-10-28 22:56:36\n",
    "@LastEditors: dkolli\n",
    "@LastEditTime: 2019-10-28 23:45:34\n",
    "'''\n",
    "import os\n",
    "# import sys\n",
    "# sys.setrecursionlimit(10000)\n",
    "\n",
    "def count_file(dir):\n",
    "    '''\n",
    "    @description: 统计指定目录大小\n",
    "    @parameters: dir\n",
    "    @return: capacity\n",
    "    '''    \n",
    "    # 容量初试值为0\n",
    "    capacity = 0\n",
    "    \n",
    "    # 获取指定目录中的所有文件夹和文件\n",
    "    dlist = os.listdir(dir)\n",
    "    \n",
    "    # 遍历所有的文件和文件夹，并将他们的大小进行累加\n",
    "    for f in dlist:\n",
    "        fullpath = os.path.join(dir, f)\n",
    "        # 将目录路径和源进行连接组成完整的路径地址\n",
    "        if os.path.isfile(fullpath):\n",
    "            # 如果得到的是一个文件，则直接计算其大小并添加至总量capacity中\n",
    "            capacity += os.path.getsize(fullpath)\n",
    "        elif os.path.isdir(fullpath):\n",
    "            # 如果得到的是一个文件夹，则通过递归调用count_file继续遍历此文件夹，进行统计\n",
    "            count_file(fullpath)\n",
    "# 返回\n",
    "    return capacity\n",
    "\n",
    "dir = 'E:\\Code\\Test\\Python\\learn_python\\Pygal'\n",
    "# 选择Pygal文件进行目录大小的统计\n",
    "print('Pygal目录下所有文件和文件夹的大小总和为：',count_file(dir))\n",
    "print('=' * 100)\n",
    "print('=' * 100)\n",
    "print('=' * 100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实现一个自动取款机的存取款模拟效果。要求有登陆和退出、查询余额、取钱，存钱等操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "========================================\n",
      "============= 系统初始化…… =============\n",
      "========================================\n",
      "请输入您的帐号：mh\n",
      "请输入您的密码：asdf\n",
      "恭喜您获得来自虚空的奖励：691474.75元\n",
      "请您登陆系统，查收奖励！\n",
      "========================================\n",
      "=========== 虚空银行管理系统 ===========\n",
      "========================================\n",
      " 1.查询余额信息     2.取钱           \n",
      " 3.存钱         4.退出系统         \n",
      "========================================\n",
      "请输出您的选择：1\n",
      "========================================\n",
      "============= 账户信息查询 =============\n",
      " |  账户名称  |      余额       |\n",
      " |     mh     |    691474.75    |\n",
      "========================================\n",
      "按回车继续：\n",
      "========================================\n",
      "=========== 虚空银行管理系统 ===========\n",
      "========================================\n",
      " 1.查询余额信息     2.取钱           \n",
      " 3.存钱         4.退出系统         \n",
      "========================================\n",
      "请输出您的选择：2\n",
      "========================================\n",
      "请输入您要取的金额：15\n",
      "========================================\n",
      "============= 账户信息查询 =============\n",
      " |  账户名称  |      余额       |\n",
      " |     mh     |    691459.75    |\n",
      "========================================\n",
      "按回车继续：\n",
      "========================================\n",
      "=========== 虚空银行管理系统 ===========\n",
      "========================================\n",
      " 1.查询余额信息     2.取钱           \n",
      " 3.存钱         4.退出系统         \n",
      "========================================\n",
      "请输出您的选择：2\n",
      "========================================\n",
      "请输入您要取的金额：-11\n",
      "您输入的有误，请重新输入一个正数。\n",
      "========================================\n",
      "请输入您要取的金额：11\n",
      "========================================\n",
      "============= 账户信息查询 =============\n",
      " |  账户名称  |      余额       |\n",
      " |     mh     |    691448.75    |\n",
      "========================================\n",
      "按回车继续：\n",
      "========================================\n",
      "=========== 虚空银行管理系统 ===========\n",
      "========================================\n",
      " 1.查询余额信息     2.取钱           \n",
      " 3.存钱         4.退出系统         \n",
      "========================================\n",
      "请输出您的选择：3\n",
      "========================================\n",
      "请输入您要存的金额：16\n",
      "========================================\n",
      "============= 账户信息查询 =============\n",
      " |  账户名称  |      余额       |\n",
      " |     mh     |    691464.75    |\n",
      "========================================\n",
      "按回车继续：\n",
      "========================================\n",
      "=========== 虚空银行管理系统 ===========\n",
      "========================================\n",
      " 1.查询余额信息     2.取钱           \n",
      " 3.存钱         4.退出系统         \n",
      "========================================\n",
      "请输出您的选择：3\n",
      "========================================\n",
      "请输入您要存的金额：-16\n",
      "您输入的有误，请重新输入一个正数。\n",
      "========================================\n",
      "请输入您要存的金额：16\n",
      "========================================\n",
      "============= 账户信息查询 =============\n",
      " |  账户名称  |      余额       |\n",
      " |     mh     |    691480.75    |\n",
      "========================================\n",
      "按回车继续：\n",
      "========================================\n",
      "=========== 虚空银行管理系统 ===========\n",
      "========================================\n",
      " 1.查询余额信息     2.取钱           \n",
      " 3.存钱         4.退出系统         \n",
      "========================================\n",
      "请输出您的选择：4\n",
      "当您退出系统，您的虚拟财产将回归虚空，请确认您的选择：Y/N?\n",
      "y\n",
      "ヾ(￣▽￣)Bye~Bye~\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "@Descripttion: \n",
    "@version: \n",
    "@Author: dkolli\n",
    "@Date: 2019-10-28 23:44:25\n",
    "@LastEditors: dkolli\n",
    "@LastEditTime: 2019-10-29 01:26:21\n",
    "'''\n",
    "# 实现一个自动取款机的存取款模拟效果。\n",
    "# 要求有登陆和退出、查询余额、取钱，存钱等操作。\n",
    "# 1、登陆初始化系统\n",
    "# 2、查询余额信息\n",
    "# 3、取钱\n",
    "# 4、存钱\n",
    "# 5、退出系统\n",
    "# 6、界面和交互\n",
    "\n",
    "import random\n",
    "\n",
    "\n",
    "# 1、系统初始化\n",
    "print('=' * 40)\n",
    "print('=' * 13, '系统初始化……', '=' * 13)\n",
    "print('=' * 40)\n",
    "bank_account={}\n",
    "bank_account['account_name'] = input('请输入您的帐号：')\n",
    "bank_account['account_passwd'] = input('请输入您的密码：')\n",
    "# 建立账户后，随机为账户生成一个奖励金额，取值在1-999999\n",
    "bank_account['balance'] = round(random.uniform(1, 999999),2)\n",
    "print('恭喜您获得来自虚空的奖励：{}元'.format(bank_account['balance']))\n",
    "print('请您登陆系统，查收奖励！')\n",
    "\n",
    "\n",
    "# 2、查询余额信息\n",
    "def show_account_info():\n",
    "    print('=' * 40)\n",
    "    print('=' * 13, '账户信息查询', '=' * 13)\n",
    "    print('{0:1}|{1:^8}|{2:^15}|'.format(' ','账户名称', '余额'))\n",
    "    print('{0:1}|{1:^12}|{2:^17}|'.format(' ',bank_account[\"account_name\"], bank_account['balance']))\n",
    "    print('=' * 40)\n",
    "\n",
    "# 这里有个疑问，为啥占位符不同，最后的输出样式一样？这里占位符到底是怎么计算的？\n",
    "\n",
    "# 测试2 2、查询余额信息\n",
    "# show_account_info()\n",
    "\n",
    "# 3、取钱\n",
    "def withdraw():\n",
    "    print('=' * 40)\n",
    "    withdraw_money = float(input('请输入您要取的金额：'))\n",
    "    if withdraw_money > 0:\n",
    "        bank_account['balance'] -= withdraw_money\n",
    "        show_account_info()\n",
    "    else:\n",
    "        print('您输入的有误，请重新输入一个正数。')\n",
    "        withdraw()\n",
    "    \n",
    "    \n",
    "# 测试3 3、取钱\n",
    "# withdraw()\n",
    "\n",
    "# 4、存钱\n",
    "def save():\n",
    "    print('=' * 40)\n",
    "    save_money = float(input('请输入您要存的金额：'))\n",
    "    if save_money > 0:\n",
    "        bank_account['balance'] += save_money\n",
    "        show_account_info()\n",
    "    else:\n",
    "        print('您输入的有误，请重新输入一个正数。')\n",
    "        save()\n",
    "\n",
    "# 测试4 4、取钱\n",
    "# save()\n",
    "\n",
    "# 5、退出系统\n",
    "def login_out():\n",
    "    print('当您退出系统，您的虚拟财产将回归虚空，请确认您的选择：Y/N?')\n",
    "    choice = input()\n",
    "    if choice == 'Y' or choice == 'y':\n",
    "        print('ヾ(￣▽￣)Bye~Bye~')\n",
    "    if choice == 'N' or choice == 'n':\n",
    "        print('舍不得钱也不是你的，嘿嘿~')\n",
    "\n",
    "\n",
    "while True:\n",
    "    # 输出一个系统交互界面：\n",
    "    print('=' * 40)\n",
    "    print('=' * 11, '虚空银行管理系统', '=' * 11)\n",
    "    print('=' * 40)\n",
    "    print('{:1}{:13}{:15}'.format(' ','1.查询余额信息','2.取钱'))\n",
    "    print('{:1}{:13}{:15}'.format(' ','3.存钱','4.退出系统'))\n",
    "    print('=' * 40)\n",
    "    # 根据键盘的输入操作值，完成相应操作。\n",
    "    key = input('请输出您的选择：')\n",
    "    if key == '1':\n",
    "        show_account_info()\n",
    "        input('按回车继续：')\n",
    "    elif key == '2':\n",
    "        withdraw()\n",
    "        input('按回车继续：')\n",
    "    elif key == '3':\n",
    "        save()\n",
    "        input('按回车继续：')\n",
    "    elif key == '4':\n",
    "        login_out()\n",
    "        break\n",
    "    else:\n",
    "        print('=' * 12, '操作无效', '=' * 12)\n",
    "        input('按回车继续：')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
